﻿using System;
using System.Text;

namespace Guids
{
    public static class GuidGenerator
    {
        public static string GetGuidFormat(GuidFormats guidFormats)
        {
            switch (guidFormats)
            {
                case GuidFormats.None:
                    return "N";

                case GuidFormats.Dashes:
                    return "D";

                case GuidFormats.Parentheses:
                    return "P";

                case GuidFormats.Hexadecimal:
                    return "X";

                case GuidFormats.CurlyBraces:
                default:
                    return "B";
            }
        }

        public static string GenerateGuid(GuidFormats guidFormat = GuidFormats.CurlyBraces, bool upperCase = false)
        {
            String format = GuidGenerator.GetGuidFormat(guidFormat);

            string guid = Guid.NewGuid().ToString(format);

            if (upperCase)
                guid = guid.ToUpper();

            return guid;
        }

        public static string GenerateMultipleGuids(int count, GuidFormats guidFormat = GuidFormats.CurlyBraces, bool upperCase = false)
        {
            if (count < 1)
                throw new ArgumentOutOfRangeException("count", "count must be greater than 0");

            String format = GuidGenerator.GetGuidFormat(guidFormat);

            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= count; i++)
            {
                String guid = GenerateGuid(guidFormat, upperCase);

                if (i == count)
                    sb.Append(guid);
                else
                    sb.AppendLine(guid);
            }

            return sb.ToString();
        }
    }
}
